<script setup>
import { ref } from 'vue'
import { userInfoService,userUpdateService } from '@/api/user.js'
import { ElMessage } from 'element-plus'
const userInfo = ref({
    id: '',
    userName: '',
    name: '',
    email: '',
})
const rules = {
    name: [
        { required: true, message: '请输入用户姓名', trigger: 'blur' },
        {
            pattern: /^\S{2,10}$/,
            message: '昵称必须是2-10位的非空字符串',
            trigger: 'blur'
        }
    ],
    email: [
        { required: true, message: '请输入用户邮箱', trigger: 'blur' },
        { type: 'email', message: '邮箱格式不正确', trigger: 'blur' }
    ]
}

//获取用户基本信息
const getUserInfo= async()=>{
  let result=await userInfoService();
  userInfo.value=result.data;
}
getUserInfo();

//提交修改信息
const updataUserInfo=async()=>{
  let result=await userUpdateService(userInfo.value);
  ElMessage.success(result.message ? result.message : "修改成功");
}
</script>
<template>
    <el-card class="page-container transparent-card">
        <template #header>
            <div class="header">
                <span>基本资料</span>
            </div>
        </template>
        <el-row>
            <el-col :span="12">
                <el-form :model="userInfo" :rules="rules" label-width="100px" size="large">
                    <el-form-item label="登录名称">
                        <el-input v-model="userInfo.userName" disabled></el-input>
                    </el-form-item>
                    <el-form-item label="积分">
                        <el-input v-model="userInfo.score" disabled></el-input>
                    </el-form-item>
                    <el-form-item label="用户昵称" prop="nickname">
                        <el-input v-model="userInfo.name"></el-input>
                    </el-form-item>
                    <el-form-item label="用户邮箱" prop="email">
                        <el-input v-model="userInfo.email"></el-input>
                    </el-form-item>
                    <el-form-item label="用户电话" prop="email">
                        <el-input v-model="userInfo.phone"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click=" updataUserInfo">提交修改</el-button>
                    </el-form-item>
                </el-form>
            </el-col>
        </el-row>
    </el-card>
</template>
<style lang="scss" scoped>
.transparent-card {
  background-color: rgba(255, 255, 255, 0.8); /* 半透明背景 */
  backdrop-filter: blur(10px); /* 模糊效果 */
  border-radius: 8px; /* 圆角 */
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); /* 可选：轻微阴影效果 */
}

</style>